package com.sanley.coronavirus.controller;

import com.github.pagehelper.PageInfo;
import com.sanley.coronavirus.common.api.CommonResult;
import com.sanley.coronavirus.entity.Dead;
import com.sanley.coronavirus.entity.User;
import com.sanley.coronavirus.service.DeadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(value = "DeadController", description = "死亡病例管理")
@RequestMapping("/dead")
public class DeadController {
    @Autowired
    DeadService service;

    @ApiOperation("所有死亡病例")
    @GetMapping(value = "/list")
    @ResponseBody
    public CommonResult list(@RequestParam(name = "page", defaultValue = "1") int page,
                             @RequestParam(name = "size", defaultValue = "25") int size,
                             @RequestParam(name = "keyword", required = false) String keyword) {
        List<Dead> deads = null;
        if (keyword != null && keyword.trim().length() != 0) {
            deads = service.findByName(keyword);
        }else {
            deads = service.findAll(page, size);
        }
        PageInfo<User> pageInfo = new PageInfo(deads);
        return CommonResult.success(pageInfo, "请求成功");
    }

}
